//
//  BiddingsController.swift
//  777Proj
//
//  Created by 陈宇 on 2017/5/15.
//  Copyright © 2017年 🐜. All rights reserved.
//

import UIKit

class BiddingsController: BaseViewController {

    override func configureLeftItem() {
        addLeftBarButtonWithImage(#imageLiteral(resourceName: "menu"))
    }
    
    lazy var childListings: [BaseViewController] = [BiddingController(.all), BiddingController(.bright), BiddingController(.dark), BiddingController(.history)]
    
    override func configureUI() {
        super.configureUI()
        
        let segmentedControl = UISegmentedControl(items: ["全部", "明标", "暗标", "历史"])
        segmentedControl.selectedSegmentIndex = 0
        navigationItem.titleView = segmentedControl
    }
    
    override func configureEvent() {
        super.configureEvent()
        
        guard let segmentedControl = navigationItem.titleView as? UISegmentedControl  else {
            return
        }
        segmentedControl.rx.selectedSegmentIndex.bind { [weak self] (selectedIndex) in
            guard let select = self?.childListings[selectedIndex], let this = self else {
                return
            }
            
            this.view.subviews.forEach({ (view) in
                view.removeFromSuperview()
            })
            
            select.view.frame = this.view.bounds
            this.view.addSubview(select.view)
            }.addDisposableTo(disposeBag)
    }

}
